import * as fgui from "fairygui-cc";
import AudioManager from "../../../../Core/Audio/AudioManager";
import EventMgr from "../../../../Core/Event/EventMgr";
import SdkTool from "../../../../Core/Sdk/SdkTool";
import TimerMgr from "../../../../Core/Timer/TimerMgr";
import { GameModels } from "../../socket/GameModels";
import ModuleWindow from "../../window/ModuleWindow";
import WindowObject from "../../window/WindowObject";
import AbstractScene from "../AbstractScene";
import UICore from "../../../../Core/Res/UICore";
import Log from "../../../../Core/Log/Log";

export class SceneMain extends AbstractScene {
    protected init(): void {
        super.init();
    }
    public enterScene(): void {
        Log.ins.log(1, `进入主场景成功`, `移除登录场景资源`, `获取小程序参数`, `获取小程序胶囊位置`, `初始化音频设置`, `检测邀请信息并弹出提示窗口`);
        ModuleWindow.ins.closeAllWindows(true);
        UICore.removePackage("Start");
        ModuleWindow.ins.openView(WindowObject.ins.MainView);
        EventMgr.on(`yaoqingrenroom`, this.onShowRoom, this);
        SdkTool.ins.sdk.getAppParam();
        SdkTool.ins.getMenuButtonBoundingClientRect();
        AudioManager.ins.setDefaultSwitchState();
        if (SdkTool.ins.isFirst) {
            this.showTeaching();
        } else {
            this.onShowRoom();
        }

    }
    private onShowRoom(): void {
        if (GameModels.lobby.RoomId == `` && SdkTool.ins.query[`roomid`]) {
            Log.ins.log(1, `检测到有邀请信息,1.5秒后弹出邀请界面`);
            TimerMgr.ins.add(1500, 1, () => {
                ModuleWindow.ins.openWindow(WindowObject.ins.AlertWindow, `是否加入${SdkTool.ins.query[`nickname`]}的房间？`, () => {
                    GameModels.lobby.send_ReqEnterRoom(SdkTool.ins.query[`roomid`]);
                    SdkTool.ins.query[`roomid`] = ``;
                });
            }, this);
        }
    }
    private showTeaching(): void {
        ModuleWindow.ins.openWindow(WindowObject.ins.AlertWindow, `首次进入游戏，是否进入教学关卡？\n完成教学关卡可领取道具奖励`, () => {
            ModuleWindow.ins.openView(WindowObject.ins.TeachView);
        });
    }
}